const path = require("path"); //必须引入
const resolve = (dir) => path.join(__dirname, dir); //必须引入
const { defineConfig } = require("@vue/cli-service");

const NODE_ENV = process.env.NODE_ENV || "development";
/**
 * 获取打包时输入的参数
 * @param argv {Array<String>}
 * @return 参数对象 {Object}
 */
function getParamsFromCommand(argv) {
  const item = {};
  if (NODE_ENV !== "development") {
    let arr = [];
    argv.forEach((v, k) => {
      if (k > 2) {
        arr = v.replace(/^-+/, "").split("=");
        item[arr[0]] = arr[1];
      }
    });
  }
  console.log(item);
  return item;
}
const { publicPath = "/", outputDir = "dist" } = getParamsFromCommand(
  process.argv
);

module.exports = defineConfig({
  transpileDependencies: true,
  publicPath,
  outputDir,
  configureWebpack: {
    devtool: process.env.NODE_ENV === "production" ? false : "source-map",
    resolve: {
      alias: {
        "@": resolve("src"),
        public: resolve("public"),
      },
    },
  },
  devServer: {
    port: "9999",
    open: true,
    proxy: {
      "/mobcoop-api": {
        target: "http://101.37.118.14/", // 测试
        changeOrigin: true,
      },
    },
  },
});
